package com.game.action;

import com.coment.po.Game;
import com.game.dao.core.GameDao;
import com.game.logic.fighting.pve.GameServiceImpl;
import com.xs.action.annotate.ActionController;
import com.xs.action.annotate.ActionMethod;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/// 1-主页操作
@RestController(value = "/homePageAction")
@ActionController(value = 1, name = "主页操作")
public class HomePageAction {
    @Resource
    private GameServiceImpl gameService;
    @Autowired
    private GameDao gameDao;

    /**
     * 1.踢出玩家并拉黑
     *
     * @param anchorInfoId 主播信息id
     * @param userInfoId   用户信息id
     */
    @GetMapping("/kickAndBlacklistPeople")
    @ActionMethod(value = 1, name = "踢出玩家,并拉黑")
    public void kickPlayer( @NotNull Integer anchorInfoId, @NotNull Integer userInfoId) {
        this.gameService.kickAndBlacklistPeople(anchorInfoId, userInfoId);
    }

    /**
     * 2.清空房间
     *
     * @param anchorInfoId 主播信息id
     */
    @GetMapping("/clear")
    @ActionMethod(value = 2, name = "清空房间")
    public void initRoom( @NotNull Integer anchorInfoId) {
        this.gameService.clear(anchorInfoId);
        Game byIdMust = gameDao.findByIdMust(anchorInfoId);
        byIdMust.userInfoIdSeat.clear();
        this.gameDao.save(byIdMust);
    }

    /**
     * 3.尝试胜利
     * @param anchorInfoId 主播信息id
     */
    @GetMapping("/attemptToWin")
    @ActionMethod(value = 3, name = "尝试胜利")
    public void attemptToWin( @NotNull Integer anchorInfoId) {
        this.gameService.attemptToWin(anchorInfoId);
    }

    /// 4.查看游戏消息
    @GetMapping("/viewGameMessages")
    @ActionMethod(value = 4, name = "查看游戏消息")
    public Game viewGameMessages(@NotNull Integer anchorInfoId) {
        return this.gameDao.findByIdMust(anchorInfoId);
    }
}
